package ua.kpi.apolonov.questions;

import java.util.List;
import ua.kpi.apolonov.answers.Answer;
import ua.kpi.apolonov.normalizers.AnswersNormalizers;
import ua.kpi.apolonov.parsers.Parsers;

/**
 * @version 4.0 12.03.2013
 * @author Yegor Apolonov
 */

public class SingleAnswerQuestion extends MultipleAnswersQuestion {

	private final int ANSWER_POSITION = 0;
	private Parsers parser = new Parsers();
	private AnswersNormalizers normalizer = new AnswersNormalizers();
	
	public SingleAnswerQuestion(String question, List<Answer> answers) {
        super(question, answers);
        setInquiry(formatAnswers() + "\nВведите номера правильных ответов\n>> ");
    }
    
	public float inspectAnswers(String userAnswers) {
        float result = 0;
        int[] userNumbers = parser.toIntArrayUserAnswer(userAnswers);
        if(userNumbers.length == 1) {
        	int answerNumber = normalizer.numberNormalizer(userNumbers[ANSWER_POSITION]);
        	if(answerNumber >= 0 && answerNumber < userNumbers.length) {
            	if(getAnswer(answerNumber).getCorrectness()) {
            		result++;
            	 }
             }
        } else { result = 0;}
        return result;
    }
}
